Make rewards-delegated-vrf and anchor-rock-paper-scissor work with SDK 'backward-compat` flag#82
Make rewards-delegated-vrf and anchor-rock-paper-scissor work with SDK 'backward-compat` flag#82snawaz wants to merge 17 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughAdds a new rewards-delegated-vrf Anchor program with state, instruction handlers, vendored ephemeral-vrf SDK and proc-macro, tests/helpers/fixtures, workspace/tooling files, example rock-paper-scissor, and switches ephemeral-rollups-sdk usages to local path with adjusted features. ChangesRewards Delegated VRF + workspace + SDK
🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested reviewers
✨ Finishing Touches🧪 Generate unit tests (beta)
|
This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@anchor-rock-paper-scissor/programs/anchor-rock-paper-scissor/Cargo.toml`:
- Line 24: The Cargo.toml entry for the dependency named ephemeral-rollups-sdk
currently uses a machine-specific absolute path; replace this with a portable
solution by removing the path attribute and either specifying a published
version (e.g., ephemeral-rollups-sdk = "x.y.z" with the required features) or
revert to a local override via a project-level .cargo/config.toml
[patch.crates-io] override; update the dependency declaration in
anchor-rock-paper-scissor's Cargo.toml (and the same dependency in
rewards-delegated-vrf's Cargo.toml) so CI and other developers do not rely on an
absolute filesystem path.
In `@rewards-delegated-vrf/programs/rewards-delegated-vrf/Cargo.toml`:
- Line 24: The Cargo.toml currently pins ephemeral-rollups-sdk to a local
absolute path (ephemeral-rollups-sdk = { path = "/Users/..."}), which breaks CI;
change that dependency to a portable reference by replacing the path entry for
ephemeral-rollups-sdk with either a published crate version (e.g.,
ephemeral-rollups-sdk = "x.y.z") or a git-based reference (e.g.,
ephemeral-rollups-sdk = { git = "https://...", tag = "vX.Y.Z" }) and preserve
any needed features like ["anchor","backward-compat"]; make the same change in
the other occurrence for anchor-rock-paper-scissor so both Cargo.toml files use
a portable version/git dependency instead of the local path.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 348db2ce-a225-4e7c-8b3c-edf16195a680
⛔ Files ignored due to path filters (1)
anchor-rock-paper-scissor/Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (2)
anchor-rock-paper-scissor/programs/anchor-rock-paper-scissor/Cargo.tomlrewards-delegated-vrf/programs/rewards-delegated-vrf/Cargo.toml
…K 'backward-compat` flag
0a9ddcd to
5d1bce9
Compare
There was a problem hiding this comment.
Actionable comments posted: 3
♻️ Duplicate comments (1)
rewards-delegated-vrf-1.0/programs/rewards-delegated-vrf/src/instructions/consume_random_reward.rs (1)
66-77:⚠️ Potential issue | 🔴 Critical | ⚡ Quick winGuard
reward.reward_mintsbefore modulo/index access.If
reward_mintsis empty, this path panics: line 73 attempts% 0(modulo by zero) and line 76 attempts[0](index out of bounds), aborting the instruction.Suggested fix
if !transfer_lookup_table.lookup_accounts.is_empty() { + require!( + !reward.reward_mints.is_empty(), + crate::errors::RewardError::InsufficientRewardMints + ); let reward_type = reward.reward_type.clone(); let mint = match reward_type {Note:
InvalidRewardConfigurationdoes not exist in the errors enum. UseInsufficientRewardMintsor define a new error type.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@rewards-delegated-vrf-1.0/programs/rewards-delegated-vrf/src/instructions/consume_random_reward.rs` around lines 66 - 77, The code currently assumes reward.reward_mints is non-empty and will panic on modulo by zero or indexing; in the consume_random_reward logic guard reward.reward_mints.is_empty() up front and return the existing InsufficientRewardMints error (or add that variant) instead of proceeding. Ensure both branches that compute mint_index (using ephemeral_vrf_sdk::rnd::random_u32 and rotate logic) and the fallback that accesses reward.reward_mints[0] are only executed when reward.reward_mints.len() > 0, and replace any reference to a non-existent InvalidRewardConfiguration with InsufficientRewardMints.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@magic-actions/programs/magic-actions/Cargo.toml`:
- Around line 24-25: Replace the machine-local absolute path for the
ephemeral-rollups-sdk dependency in Cargo.toml with a portable versioned
dependency; remove the path-based entry `ephemeral-rollups-sdk = { path = "...",
features = ["anchor-compat"] }` and instead declare a published version (e.g.,
`ephemeral-rollups-sdk = { version = "0.13.0", features = ["anchor-compat"] }`)
or the previously working version for this project so CI and other developer
machines can resolve the crate.
In `@rewards-delegated-vrf-1.0/programs/rewards-delegated-vrf/Cargo.toml`:
- Around line 25-27: Replace the machine-local absolute paths in Cargo.toml for
the ephemeral-rollups-sdk and ephemeral-vrf-sdk dependencies with portable
sources: either the relative vendor paths (e.g., use the existing vendor
directory) or published crate versions; update the entries referencing
ephemeral-rollups-sdk and ephemeral-vrf-sdk to point to the relative path inside
the repo (or a semver on crates.io) instead of "/Users/…", and remove or restore
the commented vendor line if it was the intended portable path so builds work on
other machines and CI.
In
`@rewards-delegated-vrf-1.0/programs/rewards-delegated-vrf/src/instructions/consume_random_reward.rs`:
- Around line 31-34: Replace the unchecked unwrap on the subtraction with a
proper error return using an existing RewardError variant: compute the delta
with reward_list.global_range_max as u64
.checked_sub(reward_list.global_range_min as
u64).ok_or(RewardError::RewardRangeExceedsGlobalBounds)? then set range = delta
+ 1; this ensures consume_random_reward.rs returns a typed error
(RewardRangeExceedsGlobalBounds) instead of panicking when min > max.
---
Duplicate comments:
In
`@rewards-delegated-vrf-1.0/programs/rewards-delegated-vrf/src/instructions/consume_random_reward.rs`:
- Around line 66-77: The code currently assumes reward.reward_mints is non-empty
and will panic on modulo by zero or indexing; in the consume_random_reward logic
guard reward.reward_mints.is_empty() up front and return the existing
InsufficientRewardMints error (or add that variant) instead of proceeding.
Ensure both branches that compute mint_index (using
ephemeral_vrf_sdk::rnd::random_u32 and rotate logic) and the fallback that
accesses reward.reward_mints[0] are only executed when reward.reward_mints.len()
> 0, and replace any reference to a non-existent InvalidRewardConfiguration with
InsufficientRewardMints.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: bdaba350-ead3-4499-ac2b-d4b13c7f18cf
⛔ Files ignored due to path filters (6)
anchor-counter/Cargo.lockis excluded by!**/*.lockanchor-rock-paper-scissor-1.0/Cargo.lockis excluded by!**/*.lockanchor-rock-paper-scissor/Cargo.lockis excluded by!**/*.lockmagic-actions/Cargo.lockis excluded by!**/*.lockrewards-delegated-vrf-1.0/Cargo.lockis excluded by!**/*.lockrewards-delegated-vrf/Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (10)
.github/workflows/test-examples.ymlanchor-counter/programs/public-counter/Cargo.tomlanchor-rock-paper-scissor-1.0/programs/anchor-rock-paper-scissor/Cargo.tomlanchor-rock-paper-scissor-1.0/programs/anchor-rock-paper-scissor/src/lib.rsanchor-rock-paper-scissor/programs/anchor-rock-paper-scissor/Cargo.tomlmagic-actions/programs/magic-actions/Cargo.tomlrewards-delegated-vrf-1.0/programs/rewards-delegated-vrf/Cargo.tomlrewards-delegated-vrf-1.0/programs/rewards-delegated-vrf/src/instructions/consume_random_reward.rsrewards-delegated-vrf-1.0/programs/rewards-delegated-vrf/src/lib.rsrewards-delegated-vrf/programs/rewards-delegated-vrf/Cargo.toml
| let range = (reward_list.global_range_max as u64) | ||
| .checked_sub(reward_list.global_range_min as u64) | ||
| .unwrap() | ||
| + 1; |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# First, let's examine the target file
cd rewards-delegated-vrf-1.0/programs/rewards-delegated-vrf && cat -n src/instructions/consume_random_reward.rs | head -50Repository: magicblock-labs/magicblock-engine-examples
Length of output: 2333
🏁 Script executed:
# Search for error definitions in the project
find . -name "*.rs" -type f | xargs grep -l "enum.*RewardError\|pub enum.*Error" | head -10Repository: magicblock-labs/magicblock-engine-examples
Length of output: 555
🏁 Script executed:
# Look for error module structure
find . -name "errors.rs" -o -name "error.rs" | head -5Repository: magicblock-labs/magicblock-engine-examples
Length of output: 301
🏁 Script executed:
# Check the error definitions in the targeted file
cat -n rewards-delegated-vrf-1.0/programs/rewards-delegated-vrf/src/errors.rsRepository: magicblock-labs/magicblock-engine-examples
Length of output: 4963
🏁 Script executed:
# Also check if there's error handling in the lib.rs or main module
cat -n rewards-delegated-vrf-1.0/programs/rewards-delegated-vrf/src/lib.rs | head -80Repository: magicblock-labs/magicblock-engine-examples
Length of output: 3118
Avoid unwrap() in on-chain range validation.
An invalid min/max configuration should return a typed error, not panic the program. The suggested error variant InvalidGlobalRange does not exist in the RewardError enum. Consider using an existing variant like RewardRangeExceedsGlobalBounds or add InvalidGlobalRange to the error enum first.
Suggested fix (if using existing error)
let range = (reward_list.global_range_max as u64)
.checked_sub(reward_list.global_range_min as u64)
- .unwrap()
+ .ok_or(crate::errors::RewardError::RewardRangeExceedsGlobalBounds)?
+ 1;📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| let range = (reward_list.global_range_max as u64) | |
| .checked_sub(reward_list.global_range_min as u64) | |
| .unwrap() | |
| + 1; | |
| let range = (reward_list.global_range_max as u64) | |
| .checked_sub(reward_list.global_range_min as u64) | |
| .ok_or(crate::errors::RewardError::RewardRangeExceedsGlobalBounds)? | |
| 1; |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@rewards-delegated-vrf-1.0/programs/rewards-delegated-vrf/src/instructions/consume_random_reward.rs`
around lines 31 - 34, Replace the unchecked unwrap on the subtraction with a
proper error return using an existing RewardError variant: compute the delta
with reward_list.global_range_max as u64
.checked_sub(reward_list.global_range_min as
u64).ok_or(RewardError::RewardRangeExceedsGlobalBounds)? then set range = delta
+ 1; this ensures consume_random_reward.rs returns a typed error
(RewardRangeExceedsGlobalBounds) instead of panicking when min > max.

rewards-delegated-vrf-1.0now contains a vendoredephemeral-vrf-sdkatrewards-delegated-vrf-1.0/vendor/ephemeral-vrf-sdk.Summary by CodeRabbit